package sleuthkit.util;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;

import javax.swing.JTree;

import org.apache.log4j.Logger;

import sleuthkit.gui.MainApplication;

public class CaseManagement {
	
	private static CaseManagement instance;
	private String caseName;
	private String fileSeperator = System.getProperty("file.separator");
	private static Logger log = Logger.getLogger(CaseManagement.class);
	private Case currentCase;

	private CaseManagement(String caseName) {
		super();
		this.caseName = caseName;
	}
	
	public boolean createCase(){
		
		MainApplication rootParent = MainApplication.getInstance();
		String caseRoot = rootParent.getCaseRoot();
		File caseFolder = new File(caseRoot + fileSeperator + caseName);
		caseFolder.mkdirs();
		rootParent.setCurrentCaseFolder(caseFolder);
		currentCase = new Case(caseName,caseFolder);
		
		
		return true;
	}
	
	public void setInvestigator(String investigator){
		currentCase.setInvestigator(investigator);
	}
	
	public String getCaseInfo(){
		return "not implemented yet";
		
	}
	
	public String getCase(){
		return currentCase.getCaseName();
	}
	
	public static CaseManagement getInstance(String caseName){
		if (instance==null){
			log.debug("create a new CaseManagement objekt with name " + caseName);
			instance=new CaseManagement(caseName);
		} else if (!instance.getCase().equalsIgnoreCase(caseName)){
			log.fatal("The CaseManagement is in a non acceptable stage. Wrong case name");
			return null;
		}
		return instance;
	}
	
	public static CaseManagement getInstance() {
		// TODO Auto-generated method stub
		if (instance == null){
			log.fatal("The CaseManagement is in a non acceptable stage. It needs a casename");
			System.exit(6);
		} 
		return instance; 
		
	}
	
	public Case getCurrentCase(){
		return currentCase;
	}

	public void addEvidenceFiles(ArrayList<File> evidenceFiles) {
		currentCase.addEvidence(evidenceFiles);
	}

	

	public void createCase(String selectedItem) {
		// TODO Auto-generated method stub
		
	}

	public void addEvidenceFile(File file) {
		// TODO Auto-generated method stub
		currentCase.addEvidenceFile(file);
	}
	
	public void saveCase() throws IOException{
		currentCase.save();
	}

	public void populateTree(JTree explorerViewJTree) {
		// TODO Auto-generated method stub
		currentCase.populateTree(explorerViewJTree);
	}

	public void addMemoryImageFiles(ArrayList<File> listFiles) {
		currentCase.addMemoryImage(listFiles);
	}

}
